package com.yungu.swift.assets.driver.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yungu.swift.assets.driver.dao.DriverExamineMapper;
import com.yungu.swift.assets.driver.model.dto.DriverExamineDto;
import com.yungu.swift.assets.driver.model.param.AdminExaminePageParam;
import com.yungu.swift.assets.driver.service.DriverExamineService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.SpringContextHolder;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;


/**
 * DriverExamineServiceImpl
 *
 * @author cuixiuyin
 **/
@Slf4j
@Service
public class DriverExamineServiceImpl extends BaseServiceImpl<DriverExamineDto> implements DriverExamineService {
    @Autowired
    private DriverExamineMapper driverExamineMapper;

    @Override
    protected IMapper<DriverExamineDto> getMapper() {
        return driverExamineMapper;
    }


    @Override
    public List<DriverExamineDto> exportList(AdminExaminePageParam examinePageParam) {
        return driverExamineMapper.exportList(MapUtils.convertObjToMap(examinePageParam));
    }

    @Override
    public ResponseData<Boolean> examine() {
        try {
            JdbcTemplate jdbcTemplate = SpringContextHolder.getBean(JdbcTemplate.class);
            final String sql = "{CALL P_DRIVER_EXAMINE_PROC()}";
            jdbcTemplate.execute(sql);
            return ResponseData.buildSuccessResponse("司机考核执行成功", true);
        } catch (Exception e) {
            log.error("司机考核执行失败", e);
        }
        return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "司机考核执行失败");
    }
}